/****************************************************************************
   Copyright 2013 Stacy Doss

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
****************************************************************************/

%{

#include "LefParserBase.tab.h"

extern int line_number;
extern int quote_count;
extern int expect_orient;

%}

%option noyywrap

%x VERSIONSTATE
%x QUOTESTATE

%%

VERSION						{ BEGIN(VERSIONSTATE); return VERSION; }
<VERSIONSTATE>[0-9.]*[0-9]+ { BEGIN(INITIAL); 
							  yylval.s=strdup(yytext); 
							  return VERSIONSTRING; }
NAMESCASESENSITIVE			{ return NAMESCASESENSITIVE; } 
BUSBITCHARS					{ BEGIN(QUOTESTATE); return BUSBITCHARS; }
DIVIDERCHAR					{ BEGIN(QUOTESTATE); return DIVIDERCHAR; }
<QUOTESTATE>\"				{ quote_count++;
							  if (quote_count > 1) {
								quote_count = 0;
								BEGIN(INITIAL);
							  };
							  return QUOTE; }
UNITS						{ return UNITS; }
MANUFACTURINGGRID			{ return MANUFACTURINGGRID; }
NOWIREEXTENSIONATPIN		{ return NOWIREEXTENSIONATPIN; }
USEMINSPACING				{ return USEMINSPACING; }
CLEARANCEMEASURE			{ return CLEARANCEMEASURE; }
PROPERTYDEFINITIONS			{ return PROPERTYDEFINITIONS; }
LAYER						{ return LAYER; }
MAXVIASTACK					{ return MAXVIASTACK; }
VIA							{ return VIA; }
VIARULE						{ return VIARULE; }
GENERATE					{ return GENERATE; }
NONDEFAULTRULE				{ return NONDEFAULTRULE; }
SPACING						{ return SPACING; }
SITE						{ return SITE; }
MACRO						{ return MACRO; }
PIN							{ return PIN; }
OBS							{ return OBS; }
BEGINEXT					{ return BEGINEXT; }
END							{ return END; }
LIBRARY						{ return LIBRARY; }

ON							{ return ON; }
OFF							{ return OFF; }

TIME						{ return TIME; }
NANOSECONDS					{ return NANOSECONDS; }
CAPACITANCE					{ return CAPACITANCE; }
PICOFARADS					{ return PICOFARADS; }
RESISTANCE					{ return RESISTANCE; }
OHMS						{ return OHMS; }
POWER						{ return POWER; }
MILLIWATTS					{ return MILLIWATTS; }
CURRENT						{ return CURRENT; }
MILLIAMPS					{ return MILLIAMPS; }
VOLTAGE						{ return VOLTAGE; }
VOLTS						{ return VOLTS; }
DATABASE					{ return DATABASE; }
MICRONS						{ return MICRONS; }
FREQUENCY					{ return FREQUENCY; }
MEGAHERTZ					{ return MEGAHERTZ; }

MAXXY						{ return MAXXY; }
EUCLIDEAN					{ return EUCLIDEAN; }

RANGE						{ return RANGE; }

SAMENET						{ return SAMENET; }
STACK						{ return STACK; }


CLASS						{ return CLASS; }
COVER						{ return COVER; }
BUMP						{ return BUMP; }
RING						{ return RING; }
BLOCK						{ return BLOCK; }
BLACKBOX					{ return BLACKBOX; }
PAD							{ return PAD; }
INPUT						{ return INPUT; }
OUTPUT						{ return OUTPUT; }
INOUT						{ return INOUT; }
SPACER						{ return SPACER; }
AREAIO						{ return AREAIO; }
CORE						{ return CORE; }
FEEDTHRU					{ return FEEDTHRU; }
TIEHIGH						{ return TIEHIGH; }
TIELOW						{ return TIELOW; }
ANTENNACELL					{ return ANTENNACELL; }
ENDCAP						{ return ENDCAP; }
PRE							{ return PRE; }
POST						{ return POST; }
TOPLEFT						{ return TOPLEFT; }
TOPRIGHT					{ return TOPRIGHT; }
BOTTOMLEFT					{ return BOTTOMLEFT; }
BOTTOMRIGHT					{ return BOTTOMRIGHT; }

ORIGIN						{ return ORIGIN; }
SIZE						{ return SIZE; }
BY							{ return BY; }
SYMMETRY					{ return SYMMETRY; }
X							{ return X; }
Y							{ return Y; }
R90							{ return R90; }

DIRECTION					{ return DIRECTION; }
TRISTATE					{ return TRISTATE; }

USE							{ return USE; }
SIGNAL						{ return SIGNAL; }
ANALOG						{ return ANALOG; }
GROUND						{ return GROUND; }
CLOCK						{ return CLOCK; }

TYPE						{ return TYPE; }
CUT							{ return CUT; }
IMPLANT						{ return IMPLANT; }
MASTERSLICE					{ return MASTERSLICE; }
OVERLAP						{ return OVERLAP; }
ROUTING						{ return ROUTING; }

RECT						{ return RECT; }
TOPOFSTACKONLY				{ return TOPOFSTACKONLY; }
DEFAULT						{ return DEFAULT; }
PROPERTY					{ return PROPERTY; }
FOREIGN						{ return FOREIGN; }

TO							{ return TO; }
HORIZONTAL					{ return HORIZONTAL; }
WIDTH						{ return WIDTH; }
VERTICAL					{ return VERTICAL; } 

ENCLOSURE					{ return ENCLOSURE; }
METALOVERHANG				{ return METALOVERHANG; }
OVERHANG					{ return OVERHANG; }

RPERSQ						{ return RPERSQ; }
EDGECAPACITANCE				{ return EDGECAPACITANCE; }
WIREEXTENSION				{ return WIREEXTENSION; }
CPERSQDIST					{ return CPERSQDIST; }

DCCURRENTDENSITY			{ return DCCURRENTDENSITY; }
RMS							{ return RMS; }
TABLEENTRIES				{ return TABLEENTRIES; }
OXIDE4						{ return OXIDE4; } 
ADJACENTCUTS				{ return ADJACENTCUTS; }
ANTENNAMODEL				{ return ANTENNAMODEL; }
AVERAGE						{ return AVERAGE; }
PWL							{ return PWL; }
OXIDE3						{ return OXIDE3; }
PEAK						{ return PEAK; }
OXIDE2						{ return OXIDE2; }
CUTAREA						{ return CUTAREA; }
ANTENNACUMDIFFAREARATIO		{ return ANTENNACUMDIFFAREARATIO; }
OXIDE1						{ return OXIDE1; }
ANTENNACUMAREARATIO			{ return ANTENNACUMAREARATIO; }
WITHIN						{ return WITHIN; }
ANTENNAAREAFACTOR			{ return ANTENNAAREAFACTOR; }
ACCURRENTDENSITY			{ return ACCURRENTDENSITY; }
ANTENNAAREARATIO			{ return ANTENNAAREARATIO; }
ANTENNADIFFAREARATIO		{ return ANTENNADIFFAREARATIO; }

ANTENNASIDEAREARATIO		{ return ANTENNASIDEAREARATIO; }
ANTENNACUMDIFFSIDEAREARATIO	{ return ANTENNACUMDIFFSIDEAREARATIO; }
DIFFUSEONLY					{ return DIFFUSEONLY; }
ANTENNACUMSIDEAREARATIO		{ return ANTENNACUMSIDEAREARATIO; }
ANTENNADIFFSIDEAREARATIO	{ return ANTENNADIFFSIDEAREARATIO; }
ANTENNASIDEAREAFACTOR		{ return ANTENNASIDEAREAFACTOR; }

OFFSET						{ return OFFSET; } 
PITCH						{ return PITCH; } 
AREA						{ return AREA; } 
USELENGTHTHRESHOLD			{ return USELENGTHTHRESHOLD; }
LENGTHTHRESHOLD				{ return LENGTHTHRESHOLD; } 
INFLUENCE					{ return INFLUENCE; }
SPACINGTABLE				{ return SPACINGTABLE; } 
PARALLELRUNLENGTH			{ return PARALLELRUNLENGTH; }
MINIMUMCUT					{ return MINIMUMCUT; } 
FROMBELOW					{ return FROMBELOW; } 
FROMABOVE					{ return FROMABOVE; } 
LENGTH						{ return LENGTH; }
MAXWIDTH					{ return MAXWIDTH; }
MINWIDTH					{ return MINWIDTH; } 
MINENCLOSEDAREA				{ return MINENCLOSEDAREA; } 
PROTRUSIONWIDTH				{ return PROTRUSIONWIDTH; } 
HEIGHT						{ return HEIGHT; } 
THICKNESS					{ return THICKNESS; } 
SHRINKAGE					{ return SHRINKAGE; } 
CAPMULTIPLIER				{ return CAPMULTIPLIER; } 
SLOTWIREWIDTH				{ return SLOTWIREWIDTH; } 
SLOTWIRELENGTH				{ return SLOTWIRELENGTH; } 
SLOTWIDTH					{ return SLOTWIDTH; } 
SLOTLENGTH					{ return SLOTLENGTH; } 
MAXEDGESLOTSPACING			{ return MAXEDGESLOTSPACING; }
FILLACTIVESPACING			{ return FILLACTIVESPACING; } 
MINIMUMDENSITY				{ return MINIMUMDENSITY; } 
DENSITYCHECKWINDOW			{ return DENSITYCHECKWINDOW; } 
MAXCOAXIALSLOTSPACING		{ return MAXCOAXIALSLOTSPACING; } 
DENSITYCHECKSTEP			{ return DENSITYCHECKSTEP; } 
SPLITWIREWIDTH				{ return SPLITWIREWIDTH; } 
MAXIMUMDENSITY				{ return MAXIMUMDENSITY; } 
MAXADJACENTSLOTSPACING		{ return MAXADJACENTSLOTSPACING; } 

EEQ							{ return EEQ; }
SOURCE						{ return SOURCE; }
USER						{ return USER; }
LEQ							{ return LEQ; }


N							{ if (expect_orient) {expect_orient = 0; return N; }  else {yylval.s=strdup(yytext); return NAME;}}
S							{ if (expect_orient) {expect_orient = 0; return S; }  else {yylval.s=strdup(yytext); return NAME;}}
E							{ if (expect_orient) {expect_orient = 0; return E; }  else {yylval.s=strdup(yytext); return NAME;}}
W							{ if (expect_orient) {expect_orient = 0; return W; }  else {yylval.s=strdup(yytext); return NAME;}}
FN							{ if (expect_orient) {expect_orient = 0; return FN; } else {yylval.s=strdup(yytext); return NAME;}}
FS							{ if (expect_orient) {expect_orient = 0; return FS; } else {yylval.s=strdup(yytext); return NAME;}}
FE							{ if (expect_orient) {expect_orient = 0; return FE; } else {yylval.s=strdup(yytext); return NAME;}}
FW							{ if (expect_orient) {expect_orient = 0; return FW; } else {yylval.s=strdup(yytext); return NAME;}}

\"[^\"]*\"                { yylval.s=strdup(yytext); return QSTRING; } 
[0-9]+                    { yylval.i=atoi(yytext);   return INT; }
[0-9]+\.[0-9]+            { yylval.f=atof(yytext);   return FLOAT; }
[_a-zA-Z0-9]*             { yylval.s=strdup(yytext); return NAME; }

\[                        { yylval.s=strdup(yytext); return LEFTBRACKET; }
\]                        { yylval.s=strdup(yytext); return RIGHTBRACKET; }
\{                        { yylval.s=strdup(yytext); return LEFTBRACE; }
\}                        { yylval.s=strdup(yytext); return RIGHTBRACE; }
\(                        { yylval.s=strdup(yytext); return LEFTPAREN; }
\)                        { yylval.s=strdup(yytext); return RIGHTPAREN; }
\<                        { yylval.s=strdup(yytext); return LEFTANGLE; }
\>                        { yylval.s=strdup(yytext); return RIGHTANGLE; }
\.                        { return PERIOD; }
\:                        { return COLON; }
\/                        { return BACKSLASH; }
\|                        { return PIPE; }

<QUOTESTATE>\[                        { yylval.s=strdup(yytext); return LEFTBRACKET; }
<QUOTESTATE>\]                        { yylval.s=strdup(yytext); return RIGHTBRACKET; }
<QUOTESTATE>\{                        { yylval.s=strdup(yytext); return LEFTBRACE; }
<QUOTESTATE>\}                        { yylval.s=strdup(yytext); return RIGHTBRACE; }
<QUOTESTATE>\(                        { yylval.s=strdup(yytext); return LEFTPAREN; }
<QUOTESTATE>\)                        { yylval.s=strdup(yytext); return RIGHTPAREN; }
<QUOTESTATE>\<                        { yylval.s=strdup(yytext); return LEFTANGLE; }
<QUOTESTATE>\>                        { yylval.s=strdup(yytext); return RIGHTANGLE; }
<QUOTESTATE>\.                        { return PERIOD; }
<QUOTESTATE>\:                        { return COLON; }
<QUOTESTATE>\/                        { return BACKSLASH; }
<QUOTESTATE>\|                        { return PIPE; }

\;                        { return SEMI; }
\,                        { return COMMA; }

[ \t\r]+                  /* eat up whitespace */

[\n]                      { line_number++; }

"/*""/"*([^*/]|[^*]"/"|"*"[^/])*"*"*"*/"  /* eat comments */


%%
